package com.future.hedongjun.mine.order;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.future.hedongjun.R;
import com.future.hedongjun.common.PriceHelper;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class PayActivity extends com.future.baselib.pay.PayActivity {


    @BindView(R.id.tv_price)
    TextView tvPrice;
    @BindView(R.id.tvTime)
    TextView tvTime;
    @BindView(R.id.iv_alipay)
    ImageView ivAlipay;
    @BindView(R.id.iv_wechat)
    ImageView ivWechat;
    @BindView(R.id.btn_ok)
    Button btnOk;
    private int type = 1;//支付类型

    private double price;
    private String orderNum;
    private int from;//1课程 2订单

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_pay);
        ButterKnife.bind(this);

        setTitle("支付");
        tvPrice.setText(PriceHelper.priceFormat(price));
    }

    @Override
    protected void getBundleExtras(Bundle extras) {
        super.getBundleExtras(extras);
        price = extras.getDouble("price");
        orderNum = extras.getString("orderNum");
        from = extras.getInt("from");
    }

    public static void openByClass(Context context, double price) {
        Intent intent = new Intent(context, PayActivity.class);
        intent.putExtra("price", price);
        intent.putExtra("from", 1);
        context.startActivity(intent);
    }

    public static void openByShop(Context context, double price, String orderNum) {
        Intent intent = new Intent(context, PayActivity.class);
        intent.putExtra("price", price);
        intent.putExtra("orderNum", orderNum);
        intent.putExtra("from", 2);
        context.startActivity(intent);
    }


    @Override
    public void paySuccess() {
        if (from == 1) {//课程

        }else if(from == 2){//商城
            Intent intent = new Intent(this, OrderDetailActivity.class);
            intent.putExtra("order_num",orderNum);
            startActivity(intent);
            finish();
        }
    }

    @Override
    public void payFail() {
        toast("支付失败");
    }


    @OnClick({R.id.layout_ali, R.id.layout_wechat, R.id.btn_ok})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.layout_ali:
                ivAlipay.setImageResource(R.drawable.zhifu_xz);
                ivWechat.setImageResource(R.drawable.zhifu_mr);
                type = 1;
                break;
            case R.id.layout_wechat:
                ivAlipay.setImageResource(R.drawable.zhifu_mr);
                ivWechat.setImageResource(R.drawable.zhifu_xz);
                type = 2;
                break;
            case R.id.btn_ok:
                if (type == 1) {
                    payAli(price,"河东君订单");
                } else if (type == 2){
                    payWechat(price,"河东君订单");
                }
                break;
        }
    }
}
